package com.own.business.system.menu.controller.user;

import com.own.aop.permission.PermissionModule;
import com.own.business.system.menu.business.service.SystemRolePermissionService;
import com.own.business.system.menu.common.constant.ConstantModule;
import com.own.business.system.menu.entity.map.SystemRolePermissionMapVo;
import com.own.component.client.base.RequestClientManager;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.login.util.SessionUserUtil;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * UserSystemRolePermissionController
 *
 * @author chenxueli
 * @date 2024-03-31 09:22:58
 */
@Tag(name = "系统角色权限" + ConstantBeanSuffix.MANAGE_CLIENT + ConstantBeanSuffix.CONTROLLER)
@PermissionModule(ConstantModule.MENU)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.USER_CLIENT + "system/role/permission")
public class UserSystemRolePermissionController extends BaseController {

    @Resource
    private SystemRolePermissionService systemRolePermissionService;

    @Resource
    private RequestClientManager requestClientManager;

    @Resource
    private HttpServletRequest request;

    @LogOperationAop
    @Operation(summary = "获取当前登录用户的角色权限信息列表")
    @GetMapping("/self")
    public ResultModel<List<SystemRolePermissionMapVo>> self() {
        var loginUser = SessionUserUtil.getLoginUser();
        // 获取客户端信息
        var client = requestClientManager.client(request);
        var list = systemRolePermissionService.listByUserId(loginUser.userId(), client);
        return R.success(list.stream().map(SystemRolePermissionMapVo::new).toList());
    }

}
